<?php
$start=0;
$end=0;
$page; 
$total_pages;
// This function use for Navigation Calculation
// Input  : database Name,query 
// Output : Limit paramiter, total page number,   
function resolve($db_name, $query_Search){
	global $page; 
	if(isset($_REQUEST['page']))
	{
		$page=$_REQUEST['page'];
	}else{
		$page=1;
	} // This is for link pages 

	$CompanySear=mysql_db_query($db_name,$query_Search);
	//$totalResordCount=mysql_fetch_array($CompanySear);
	//$totalItem = $totalResordCount[0];
	$totalItem = mysql_num_rows($CompanySear);
	//echo $totalItem;
	
	$per_page=25; //How many Item show in perpage give this value here 

	global $total_pages;
	
	$total_pages=ceil($totalItem/$per_page);
	//echo $total_pages;
	global $start; 
	global $end; 
 

	$start=($page-1) * $per_page;
	$end= $per_page;
}

/////Start Navigation Function
function func_paging_home($page, $total_pages)
 {
	$url=$_SERVER['REQUEST_URI'];
	if(strpos($url,"page")>0)
	{
		$link=str_replace("page=".$page,"page",$url); 
	}else
	 	
		$link.=$url."&page";
	 	if($page > 1)
		{
			$new_url=$link."=".($page-1);
			echo "<a href=".$new_url." style='text-decoration:none'>"."<font face='Verdana' size='2'>Previous</font>"."</a>&nbsp;&nbsp;";
		}		
	  	if($total_pages>2) ///2+1=3 Pages at a view (9+1=10)
		{
			$cnter = $total_pages-$page;
			if($cnter>2) ////9+1=10
	  		{
	   			if($page>2){ ///9
	     		$start=$page-1; ///5 ahead
		 		$limiter=$page+1; //
			}
			else{   
	   			$start=1;
	   			$limiter=$start+2; ///9
	    		}	   
	  	}
	  	else
	   	{ 
	   		if($page==$total_pages)
			{
	   			$start=$total_pages-2; //9
	   			$limiter=$total_pages;
	   		}
	   		else
	   		{
	   			$start=$page-1;//5
	   			$limiter=$page+1;//5
	   		}
	   }
	}  
	else
	{	
	    $start=1;
		$limiter=$total_pages;  
	}
	
	for($i=$start; $i<=$limiter; $i++)	
	{
		$new_url=$link."=".$i;
		
		if($i==$page)
			echo "<a href=".$new_url." style='text-decoration:none'><font face='Verdana' size='2' color=RED>".$i."</font></a>&nbsp;&nbsp;";
		else
			echo "<a href=".$new_url." style='text-decoration:none'><font face='Verdana' size='2'>".$i."</font></a>&nbsp;&nbsp;";		
	}
			
	if($page < $total_pages)
	{
		$new_url=$link."=".($page+1);
		echo "<a href=".$new_url." style='text-decoration:none'>"."<font face='Verdana' size='2'>Next</font>"."</a> ";
	}		
}//End of Navigation function

?>
